﻿using System;
using System.Text;

using Microsoft.WowAddonStudio.Lua.Model;

namespace Microsoft.WowAddonStudio.Lua.LanguageService.Intellisense
{
    public class FunctionDescriptionProvider : DescriptionProvider<Function>
    {
        public override string GetDescription(Function function)
        {
            if (function == null)
                throw new ArgumentNullException("function");

            var descriptionBuilder = new StringBuilder(function.GetSignature());

            var summary = function.GetSummary();
            if (summary != null)
            {
                descriptionBuilder.AppendLine();
                descriptionBuilder.Append(summary);
            }

            if (function.Returns != null && function.Returns.Length > 0)
            {
                descriptionBuilder.AppendLine();
                descriptionBuilder.AppendLine();
                descriptionBuilder.AppendLine("Returns:");

                for (int i = 0; i < function.Returns.Length; i++)
                {
                    descriptionBuilder.AppendFormat("  {0} - {1}", function.Returns[i].GetName(), function.Returns[i].GetSummary());
                    if (function.Returns.Length - i > 1)
                        descriptionBuilder.AppendLine();
                }
            }

            return descriptionBuilder.ToString();
        }
    }
}
